package com.telecom.controller.user;

import com.telecom.common.convention.result.PageDTO;
import com.telecom.common.convention.result.Result;
import com.telecom.pojo.dto.user.meal.UserMealPageQueryRequestDTO;
import com.telecom.pojo.vo.user.meal.UserMealDetailVO;
import com.telecom.pojo.vo.user.meal.MealItemVO;
import com.telecom.service.MealService;
import jakarta.validation.constraints.Positive;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import jakarta.annotation.Resource;

import jakarta.validation.Valid;

/**
 * 用户套餐相关接口
 */
@RestController
@RequestMapping("/user/meal")
@Slf4j
public class MealController {

    @Resource
    private MealService mealService;

    /**
     * 分页条件查询套餐
     * 
     * @param queryRequest 查询条件参数
     * @return 套餐列表分页结果
     */
    @GetMapping("/page")
    public Result<PageDTO<MealItemVO>> page(@Valid UserMealPageQueryRequestDTO queryRequest) {
        log.info("套餐分页查询:{}",queryRequest);
        PageDTO<MealItemVO> pageResult = mealService.userPage(queryRequest);

        return Result.success(pageResult);
    }

    /**
     * 根据套餐id查询详细
     *
     * @param id 套餐ID
     * @return 套餐详情
     */
    @GetMapping("/{id}")
    public Result<UserMealDetailVO> getById(@PathVariable @Positive(message = "套餐ID必须为正数") Long id) {
        log.info("查询套餐详情，根据id：{}",id);
        UserMealDetailVO userMealDetailVO = mealService.userGetMealDetailById(id);

        return Result.success(userMealDetailVO);
    }


}
